/*
 * DialogCurrencyView.java
 *
 * Created on Sep 12, 2012, 8:19:50 PM
 */
package editor.windows;

import adventure.AdventureEdit;
import adventure.misc.CurrencyEdit;

/**
 *
 * @author Michael Hanns
 * 
 */
public class DialogCurrencyView extends javax.swing.JDialog {

    
    AdventureEdit adv;
    CurrencyEdit currency;
    WITNAFrameView parent;

    /** Creates new form DialogCurrencyView */
    public DialogCurrencyView(javax.swing.JFrame parent, AdventureEdit adv) {
        super(parent, true);
        initComponents();
        this.parent = (WITNAFrameView)parent;
        this.adv = adv;
        this.currency = (CurrencyEdit) adv.getCurrency();
        fillInForm();
    }

    private void fillInForm() {
        nameField.setText(currency.getStatusID());
        singularField.setText(currency.getSingular());
        pluralField.setText(currency.getPlural());
        singularDarkField.setText(currency.getSingularInDark());
        pluralDarkField.setText(currency.getPluralInDark());
    }

    private void applyChanges() {
        if (!currency.getStatusID().equals(nameField.getText())) {
            currency.setStatusID(nameField.getText());
            parent.printToConsole("Module currency name changed to " + nameField.getText() + ".");
        }
        if (!currency.getSingular().equals(singularField.getText())) {
            currency.setSingular(singularField.getText());
            parent.printToConsole("Module singular currency changed to " + singularField.getText() + ".");
        }
        if (!currency.getPlural().equals(pluralField.getText())) {
            currency.setPlural(pluralField.getText());
            parent.printToConsole("Module plural currency changed to " + pluralField.getText() + ".");
        }
        if (!currency.getSingularInDark().equals(singularDarkField.getText())) {
            currency.setSingularInDark(singularDarkField.getText());
            parent.printToConsole("Module singular currency (in dark) changed to " + singularDarkField.getText() + ".");
        }
        if (!currency.getPluralInDark().equals(pluralDarkField.getText())) {
            currency.setPluralInDark(pluralDarkField.getText());
            parent.printToConsole("Module plural currency (in dark) changed to " + pluralDarkField.getText() + ".");
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        nameField = new javax.swing.JFormattedTextField();
        usageDarkLabel = new javax.swing.JLabel();
        usageDarkPanel = new javax.swing.JPanel();
        singularDarkLabel = new javax.swing.JLabel();
        pluralDarkLabel = new javax.swing.JLabel();
        singularDarkField = new javax.swing.JFormattedTextField();
        pluralDarkField = new javax.swing.JFormattedTextField();
        cancelButton = new javax.swing.JButton();
        applyButton = new javax.swing.JButton();
        nameLabel = new javax.swing.JLabel();
        usagePanel = new javax.swing.JPanel();
        singularLabel = new javax.swing.JLabel();
        pluralLabel = new javax.swing.JLabel();
        singularField = new javax.swing.JFormattedTextField();
        pluralField = new javax.swing.JFormattedTextField();
        okButton = new javax.swing.JButton();
        usageLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Edit Currency..");

        usageDarkLabel.setText("Usage (in dark):");

        usageDarkPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        singularDarkLabel.setText("Singular:");

        pluralDarkLabel.setText("Plural:");

        org.jdesktop.layout.GroupLayout usageDarkPanelLayout = new org.jdesktop.layout.GroupLayout(usageDarkPanel);
        usageDarkPanel.setLayout(usageDarkPanelLayout);
        usageDarkPanelLayout.setHorizontalGroup(
            usageDarkPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(usageDarkPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(usageDarkPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(singularDarkLabel)
                    .add(pluralDarkLabel))
                .add(18, 18, 18)
                .add(usageDarkPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(pluralDarkField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE)
                    .add(singularDarkField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE))
                .addContainerGap())
        );
        usageDarkPanelLayout.setVerticalGroup(
            usageDarkPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(usageDarkPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(usageDarkPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(singularDarkLabel)
                    .add(singularDarkField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(usageDarkPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(pluralDarkLabel)
                    .add(pluralDarkField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        applyButton.setText("Apply");
        applyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                applyButtonActionPerformed(evt);
            }
        });

        nameLabel.setText("Name:");

        usagePanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        singularLabel.setText("Singular:");

        pluralLabel.setText("Plural:");

        org.jdesktop.layout.GroupLayout usagePanelLayout = new org.jdesktop.layout.GroupLayout(usagePanel);
        usagePanel.setLayout(usagePanelLayout);
        usagePanelLayout.setHorizontalGroup(
            usagePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(usagePanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(usagePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(singularLabel)
                    .add(pluralLabel))
                .add(18, 18, 18)
                .add(usagePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(pluralField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE)
                    .add(singularField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE))
                .addContainerGap())
        );
        usagePanelLayout.setVerticalGroup(
            usagePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(usagePanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(usagePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(singularLabel)
                    .add(singularField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(usagePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(pluralLabel)
                    .add(pluralField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        okButton.setText("OK");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        usageLabel.setText("Usage:");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(nameLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(nameField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, usagePanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, usageDarkPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(usageLabel)
                            .add(usageDarkLabel))
                        .add(0, 0, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(0, 0, Short.MAX_VALUE)
                        .add(okButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(cancelButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(applyButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(nameLabel)
                    .add(nameField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(usageLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(usagePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(usageDarkLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(usageDarkPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(okButton)
                    .add(cancelButton)
                    .add(applyButton))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void applyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyButtonActionPerformed
        applyChanges();
    }//GEN-LAST:event_applyButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        dispose();
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        applyChanges();
        dispose();
    }//GEN-LAST:event_okButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton applyButton;
    private javax.swing.JButton cancelButton;
    private javax.swing.JFormattedTextField nameField;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JButton okButton;
    private javax.swing.JFormattedTextField pluralDarkField;
    private javax.swing.JLabel pluralDarkLabel;
    private javax.swing.JFormattedTextField pluralField;
    private javax.swing.JLabel pluralLabel;
    private javax.swing.JFormattedTextField singularDarkField;
    private javax.swing.JLabel singularDarkLabel;
    private javax.swing.JFormattedTextField singularField;
    private javax.swing.JLabel singularLabel;
    private javax.swing.JLabel usageDarkLabel;
    private javax.swing.JPanel usageDarkPanel;
    private javax.swing.JLabel usageLabel;
    private javax.swing.JPanel usagePanel;
    // End of variables declaration//GEN-END:variables
}
